import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop_z/config/service_url.dart';
import 'package:flutter_shop_z/pages/details_page.dart';

class HotGoods extends StatelessWidget {
  final List hotgoodsList;
  HotGoods(this.hotgoodsList);
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          _title,
          _hotGoodsList(context),
        ],
      ),
    );
  }

  Widget _title = Container(
    padding: EdgeInsets.only(left: ScreenUtil().setWidth(280)),
    width: ScreenUtil().setWidth(750),
    height: ScreenUtil().setHeight(100),
    decoration: BoxDecoration(
        color: Colors.white,
        border: Border(bottom: BorderSide(color: Colors.black12, width: 1))),
    child: Row(
      children: <Widget>[
        Image.asset(
          "images/huo.png",
          width: ScreenUtil().setHeight(40),
        ),
        Text(
          "火爆专区",
          style: TextStyle(
              color: Color.fromRGBO(216, 30, 6, 1.0),
              fontSize: ScreenUtil().setSp(40)),
        )
      ],
    ),
  );

  Widget _hotGoodsList(context) {
    if (hotgoodsList != null) {
      List<Widget> _widgetList = hotgoodsList.map((value) {
        return InkWell(
          onTap: () {
            Navigator.push(context, MaterialPageRoute(builder: (context) {
              return new DetailsPage(value['commodityId']);
            }));
          },
          child: Container(
            width: ScreenUtil().setWidth(372),
            color: Colors.white,
            padding: EdgeInsets.all(5),
            margin: EdgeInsets.only(bottom: 3),
            child: Column(
              children: <Widget>[
                Image.network(
                  "${serviceUrl}goods/${value['categoryId']}/${value['categorySubId']}/${value['commodityImg']}",
                  width: ScreenUtil().setWidth(372),
                  fit: BoxFit.fill,
                ),
                Text("${value['commodityName']}",
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        color: Colors.purple,
                        fontSize: ScreenUtil().setSp(26))),
                Row(
                  children: <Widget>[
                    Text("￥${value['commodityDiscountPrice']}"),
                    Text(
                      "￥${value['commodityOriginalPrice']}",
                      style: TextStyle(
                          decoration: TextDecoration.lineThrough, //删除线
                          color: Colors.black12),
                    )
                  ],
                ),
              ],
            ),
          ),
        );
      }).toList();

      return Wrap(
        spacing: 2,
        children: _widgetList,
      );
    } else {
      return Text("没有数据了");
    }
  }
}
